/*
 * @FilePath     : /layui/routes/xm-select.js
 * @Description  :
 * @Date         : 2025-02-21 17:17
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-24 16:36
 */
const express = require('express')

const router = express.Router()

// 1）路由1：测试当前路由模块；
router.get('/', (req, res) => {
  res.send('当前是 xm-select 路由模块')
  // 验证见 Apifox
})

// 2）路由2：远程分页
router.get('/remote-search1', (req, res) => {
  // 用随机数模拟获取失败
  const theNum = Math.random()
  console.log('/remote-search1 接口生成的随机数 —— 模拟成功或失', theNum)
  if (theNum > 0.5) {
    res.json({
      code: 0,
      msg: '获取远程数据成功',
      data: [
        {
          name: '选项1',
          value: 1,
        },
        {
          name: '选项2',
          value: 2,
          selected: true,
        },
        {
          name: '选项3',
          value: 3,
        },
        {
          name: '选项4',
          value: 4,
        },
      ],
      totalPage: 7,
    })
  } else {
    res.json({
      code: 204,
      msg: '未查询到数据',
    })
  }
})

module.exports = router
